package com.ehome.poct.base.dao.device.repository;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ehome.core.page.Page;
import com.ehome.mybatisplus.support.AbstractCrudRepository;
import com.ehome.poct.base.api.dto.device.QrCodeHisDetailDTO;
import com.ehome.poct.base.api.dto.device.TestDeviceQrcodePrintHisDTO;
import com.ehome.poct.base.api.vo.device.QrcodePrintHisDetVO;
import com.ehome.poct.base.api.vo.device.QrcodePrintHisVO;
import com.ehome.poct.base.dao.device.entity.TestDeviceQrcodePrintHisDO;
import com.ehome.poct.base.dao.device.entity.TestDeviceQrcodePrintHisHeadDO;
import com.ehome.poct.base.dao.device.mapper.TestDeviceQrcodePrintHisHeadMapper;
import com.ehome.poct.base.dao.device.mapper.TestDeviceQrcodePrintHisMapper;
import com.ehome.poct.base.dao.mapping.DeviceQrcodePrintMapping;
import com.ehome.poct.base.device.repository.TestDeviceQrcodePrintHisRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

/**
 * 打印记录详细RepositoryImpl
 *
 * @author ehome
 * @Date 2022-07-14 15:54
 */
@Repository
public class TestDeviceQrcodePrintHisRepositoryImpl extends AbstractCrudRepository<TestDeviceQrcodePrintHisDO, TestDeviceQrcodePrintHisDTO> implements TestDeviceQrcodePrintHisRepository {
    @Autowired
    private TestDeviceQrcodePrintHisMapper mapper;
    @Autowired
    private DeviceQrcodePrintMapping printMapping;

    @Override
    public Page<QrcodePrintHisDetVO> pageList(QrCodeHisDetailDTO req)
    {
        var pagedatas = mapper.selectPage(new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>(req.getPageIndex(),req.getPageSize()),

                Wrappers.<TestDeviceQrcodePrintHisDO>lambdaQuery()
                        .eq(ObjectUtil.isNotEmpty(req.getPrintDate()),TestDeviceQrcodePrintHisDO::getPrintDate,req.getPrintDate())
                        .eq(ObjectUtil.isNotEmpty(req.getSno()),TestDeviceQrcodePrintHisDO::getSno,req.getSno())
                        .eq(ObjectUtil.isNotEmpty(req.getDeviceBatch()),TestDeviceQrcodePrintHisDO::getDeviceBatch,req.getDeviceBatch())
                        .eq(ObjectUtil.isNotEmpty(req.getDeviceType()),TestDeviceQrcodePrintHisDO::getDeviceType,req.getDeviceType())
                        .le(ObjectUtil.isNotEmpty(req.getEndTime()), TestDeviceQrcodePrintHisDO::getCreateTime, req.getEndTime())
                        .ge(ObjectUtil.isNotEmpty(req.getStartTime()), TestDeviceQrcodePrintHisDO::getCreateTime, req.getStartTime())
                .orderByDesc(TestDeviceQrcodePrintHisDO::getCreateTime));
        Page<QrcodePrintHisDetVO> page = new Page<>();
        page.setCurrent((int) pagedatas.getCurrent());
        page.setSize((int) pagedatas.getSize());
        page.setTotal((int)pagedatas.getTotal());
        page.setList(printMapping.toDetailList(pagedatas.getRecords()));
        return page;
    }
}
